SlideShare a Scribd company logo
1 of 32
+
Object Oriented Analysis
Software Analysis and Design
Michael Heron
+
Introduction
īŽ In this lecture we’re going to begin discussing how we actually
go about developing a complex program.
īŽ And we’ll do it through the medium of object orientation.
īŽ This is likely to be a somewhat alien way to approach a
problem for many of you.
īŽ One of the great lies of object orientation is that it is ‘easy because it
mirrors the way people think’
īŽ However, it is the conceptual understanding that will enable you
to build very complex programs as time goes by.
īŽ It’s a very powerful way to build functionality.
+
An Object Oriented System
īŽ A properly designed object oriented system consists of:
īŽ One or more objects.
īŽ These objects are defined by classes.
īŽ Each object consists of:
īŽ Attributes
īŽ Behaviours
īŽ Attributes contain information about the object.
īŽ Data
īŽ Behaviours are instructions for acting upon that data.
+
The Structure of an Object
īŽ First, we must define what we mean by an object.
īŽ In terms of object oriented programming.
īŽ An object is an instance of a class.
īŽ A class is like a blueprint telling the object what structure it has.
īŽ A class defines:
īŽ Attributes
īŽ Behaviours
īŽ The object defines
īŽ The state of attributes.
īŽ The values that each piece of data has.
+
Eh?
īŽ Let’s look at in the abstract.
īŽ There exists, somewhere, a blueprint for a chair.
īŽ Blueprints for the chairs on which you are sitting.
īŽ The blueprint defines what the chair looks like.
īŽ It defines the structure of the chair
īŽ It defines the relationship of the legs to the seat
īŽ This blueprint would be the class.
īŽ The specific chairs on which you are sitting would be objects.
īŽ They were made (instantiated) from that blueprint.
+
Uhâ€Ļ
īŽ The blueprint tells us how the chair is supposed to behave and
what information about that chair may be mutable.
īŽ The colour of the chair
īŽ The material of the chair
īŽ The size of the chair
īŽ The class says:
īŽ A chair has a colour, material, and size
īŽ The object says:
īŽ I am blue, made of leather, and am medium sized.
īŽ Different chairs can have the same basic structure, but different
states.
īŽ I am pink, made of suede, and am large.
+
Okay!
īŽ We’ll come back to this subject later.
īŽ Because regardless of what people may tell you, object orientation
does not come naturally to most people.
īŽ This however is going to be the fundamental bedrock of the systems
we analyse in the coming weeks.
īŽ The programming languages you use throughout this course
are object oriented languages.
īŽ Visual Basic .NET
īŽ Java
īŽ C#
īŽ The objects may not be emphasized to begin with.
īŽ But they’re coming.
+
Attributes
īŽ The class defines what attributes will be present in an object.
īŽ It has these.
īŽ We don’t know what they are yet.
īŽ Attributes are things that an object will have.
īŽ Usually things that are mutable (they can change).
īŽ Consider a human face.
īŽ It has eyes
īŽ It has a nose
īŽ It has a mouth
īŽ These are modeled in a computer program as variables.
īŽ A class is thus a collection of variables.
+
Behaviours
īŽ As well as these variables, a class contains behaviours for
acting upon those variables.
īŽ If the class is a human face:
īŽ Attributes: Eyes, Mouth, Nose
īŽ Behaviours: blink, smile, sniff
īŽ These are modeled in a computer program as functions.
īŽ Also called methods.
īŽ Two names for the same thing, we’ll use these interchangeably.
īŽ Behaviours / Functions / Methods
īŽ Different words, all for the same basic concept.
+
Behaviours
īŽ Behaviours can be broken down into further parts.
īŽ Behaviours may have variables of their own.
īŽ Temporary variables that only exist as long as the method is
executing.
īŽ These are known as ‘local variables’ in programming.
īŽ They have a limited scope within which they can be accessed.
īŽ Behaviours will usually incorporate programming structures.
īŽ Some structures allow the programmer to choose between
courses of actions.
īŽ Some structures allow the programmer to repeat blocks of code.
īŽ Behaviours will incorporate flow control.
+
Class Diagrams
īŽ One of the reasons why software development has such a
complex vocabulary of jargon is the need for experts to
communicate succinctly.
īŽ This is what all formal software design techniques are about.
īŽ In order for us to begin talking about how to discuss programs,
we need some kind of share vocabulary.
īŽ We don’t know how to really use them yet, but let’s talk about
how we can represent a class in a modeling language.
īŽ In this case, the language is UML
īŽ Unified Modelling Language
+
Object Oriented Programs
īŽ Object oriented programs introduce new complexities of
interaction.
īŽ Objects have a relationship to classes.
īŽ Objects may be composed of other objects.
īŽ Objects define their own behaviours and attributes.
īŽ Objects can offer several levels of indirection to other objects.
īŽ Gaining a clear perspective on how an object oriented program
fits together is key to developing and maintaining OO code.
īŽ Which is what our analysis and design eventually leads towards.
+
Object Relationships
īŽ Objects can contain references to other objects.
īŽ This is known as composition.
īŽ This is a has a relationship.
īŽ Composition relationships also imply a multiplicity (or
cardinality).
īŽ Where there is a 0 or 1 relationship, it is known as a composition.
īŽ Where it is more, it is an aggregation.
īŽ Formal UML notations have more precise differentiations of
composition.
īŽ That’s for Future Us to worry about.
+
Object Relationships
īŽ An object may be a specialisation of another object.
īŽ This is known as inheritance in object orientation.
īŽ This is a is a relationship.
īŽ More specialised forms of inheritance exist.
īŽ We’ll talk about these as we go along.
īŽ For now, we’ll just use the one kind.
īŽ The class from which another class inherits is called the parent.
īŽ Or Super class.
īŽ The class that does the inheriting is called the child.
īŽ Or sub class.
+
Examples
īŽ A Car:
īŽ Has an engine (composition)
īŽ Has four wheels (aggregation)
īŽ Has 2 or more doors (aggregation)
īŽ Is a vehicle (inheritance)
īŽ A Kitten:
īŽ Has four legs (aggregation)
īŽ Is an animal (inheritance)
īŽ Has a tail (composition)
īŽ Has the property of being as cute as the dickens (composition)
+
Object Oriented Programs
īŽ The relationship between objects and classes becomes very
complex in many computer programs.
īŽ We’ll see this before too long when we return to our case study.
īŽ Some means of representing this complexity ‘at a glance’ is
useful.
īŽ This is what a class diagram is used for.
īŽ It gives the static view of a program’s architecture.
īŽ It doesn’t change when the programming is running.
īŽ Other techniques exist too.
īŽ They vary in effectiveness.
+
Class Diagrams
īŽ At their simplest, class diagrams are just boxes with lines
connecting them to other boxes.
īŽ They show the relationship between classes only.
+
Class Diagrams
īŽ At the next level of usefulness, class diagrams also contain
information about attributes and methods.
īŽ Attributes in the second row
īŽ Methods in the third
īŽ At their best, class diagrams contain class relationships,
methods, attributes, and the visibility of each.
īŽ They also explicitly show multiplicity.
īŽ Class diagrams are the most fundamental unit of UML.
īŽ And also the most useful.
īŽ If you only ever take one diagraming notation to heart, let it be this
one.
+
Class Diagram with Attributes
+
Why Use A Class Diagram?
īŽ There are several reasons why using a class diagram leads to
a more complete view of a project.
īŽ It shows the relationship between classes in a way that allows you
to trace accessibility.
īŽ It shows at a glance the amount of coupling in a project.
īŽ It shows at a glance the amount of cohesion in a project.
īŽ It shows at a glance the impact of change.
īŽ These are elements that tell us ‘how good an OO design we
have’
īŽ That’s an incredibly difficult thing to assess at the moment, which is
one of the reasons why OOP is so hard to learn.
+
Coupling and Cohesion
īŽ One of the biggest problems OO developers have is ensuring a
good OO design.
īŽ What is a good OO design, you ask?
īŽ Certainly for people unfamiliar with how OO is best done, it’s
hard to objectively rate an object architecture.
īŽ ‘Uh, sure – it’s ten good?’
īŽ Two objective measures exist for this though.
īŽ Coupling
īŽ Cohesion
īŽ As a rule, we are aiming for high cohesion and low coupling.
+
Coupling
īŽ Coupling relates to the amount of interconnectedness of
classes.
īŽ We want this to be as low as is reasonably possible.
īŽ There’s a reason why we don’t just link classes up in every possible
way.
īŽ A coupling relationship is any composition, aggregation, or
inheritance.
īŽ We can’t get away from these, but we can limit them.
īŽ The more connections made between objects and classes, the
harder it is to make any changes.
īŽ Because of the knock-on effect associated.
+
Coupling
īŽ If your program has high coupling, there are several
disadvantages built in:
īŽ Changes in one object may result in unexpected side-effects
elsewhere in a program.
īŽ Often the cause is not at all obvious.
īŽ Classes are difficult to understand at a glance.
īŽ They make use of so much external functionality.
īŽ Classes are difficult to test.
īŽ They cannot be easily extracted from their context.
īŽ We aim for low coupling, of the right kind of coupling.
īŽ More on that later.
+
Cohesion
īŽ Cohesion is the level to which an object adheres to a single set
of responsibilities.
īŽ We want this as high as is reasonably possible.
īŽ In a good object oriented program, each object has one firmly
defined responsibility.
īŽ A cat object would not be responsible for keeping track of its
owner’s employment.
īŽ A car object would not be responsible for storing the name of the
garage where it gets services.
īŽ Good OO design requires us to make classes that have unique,
specific responsibilities.
+
Cohesion
īŽ The dangers that come from low cohesion are the same as that
of high coupling.
īŽ They’re really just two ways of reflecting the same basic concept.
īŽ Low cohesion is an insidious problem.
īŽ Programs with low cohesion tend to become even less coherent
over time.
īŽ It is a consequence of badly analysed and badly designed
programs.
īŽ You’ll learn how to do this properly in third year.
+
The Tension of OO Development
īŽ Object Oriented programs are a tension between coupling and
cohesion.
īŽ We increase cohesion by increasing coupling.
īŽ We reduce coupling by decreasing cohesion.
īŽ As OO developers we have to find a happy medium between
the two.
īŽ In some cases, simple rationalization of a design can remove
problems.
īŽ That is a judgment call that comes from experience.
īŽ We’ll have plenty of opportunities to do this as we go through
the module.
+
Impact of Change
īŽ Both of these concepts are a way of objectively rating the
impact of change in a program.
īŽ What makes a program easy to work with?
īŽ Clearly written code.
īŽ Comments (seriously)
īŽ Changes do not have unexpected consequences.
īŽ The latter of these three is what the impact of change defines.
īŽ That when we change a piece of code, we know what is going to be
changed as a result of it.
+
Impact of Change
īŽ One of the reasons we restrict visibility of variables and
methods is to manage the impact of change.
īŽ If you are a Respectful Developer, you avoid making changes that
will impact on code you did not write.
īŽ Lest terrible vengeance be visited upon you and your kith and kin
īŽ The lower the visibility, the better.
īŽ Changing a local variable for example only impacts the method in
which it is defined.
īŽ Changing a class wide attribute will potentially impact on every
method in the class.
+
Impact of Change
īŽ In a multi-developer environment you have to assume that if
functionality is available, it has been used.
īŽ Someone saw your calculate_awesome() method and thought ‘hey,
that does exactly what I want’
īŽ If it can be used, you can’t idly make structural changes.
īŽ Refactoring is fine
īŽ Redesign is not
īŽ We’ll talk more about refactoring in a later lecture.
īŽ It basically means ‘improving code so well that nobody notices’
+
The Class Diagram
īŽ The best quality of class diagrams shows the impact of change
at a glance.
īŽ Where there are lots of arrows, there be coupling issues.
īŽ Where there are huge lists of methods and attributes in a class,
there be likely cohesion problems.
īŽ Where there are lots of public methods and attributes, there be likely
impact of change issues.
īŽ Doing the class diagram from the start gives us a good
opportunity to identify structural problems before we write a
single line of code.
+
The Class Diagram
īŽ In multi-developer projects, the class diagram represents the
‘best understanding’ of how a program is being developed.
īŽ It’s kind of an informal contract with your fellow developers.
īŽ One of the benefits we get from object orientation is an ease of
development and integration.
īŽ But only if everyone is communicating effectively.
īŽ It is important that this diagram remain up to date with the state
of the program.
īŽ It is a ‘living document’.
īŽ Some tools exist for automatically generating them.
īŽ And generating program code from class diagrams.
+
Conclusion
īŽ Class diagrams are awesome.
īŽ Seriously, you need to believe me on that.
īŽ They give us a neat way of representing a number of issues
with our programs.
īŽ How classes relate
īŽ The degree of coupling
īŽ The degree of cohesion
īŽ The likely impact of change.
īŽ We can tell at a glance when our systems are going off the
rails.
īŽ Huzzah.

More Related Content

What's hot

Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven DesignHarsh Jegadeesan
 
Data Modeling Er
Data Modeling ErData Modeling Er
Data Modeling Er1ajnabi4u
 
Lecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASELecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASEbabak danyal
 
2 er
2 er2 er
2 erELIMENG
 
Understanding unified modelling language
Understanding unified modelling languageUnderstanding unified modelling language
Understanding unified modelling languageEmmanuel Kumah
 
06 class diagrams
06 class diagrams06 class diagrams
06 class diagramsBaskarkncet
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modellingDr. C.V. Suresh Babu
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Modelguest8fdbdd
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship DiagramShakila Mahjabin
 
Behavioural modelling
Behavioural modellingBehavioural modelling
Behavioural modellingBenazir Fathima
 
Ch 5 O O Data Modeling
Ch 5  O O  Data ModelingCh 5  O O  Data Modeling
Ch 5 O O Data Modelingguest8fdbdd
 
39f1b9a797dbms chapter2 b.sc2
39f1b9a797dbms chapter2 b.sc239f1b9a797dbms chapter2 b.sc2
39f1b9a797dbms chapter2 b.sc2Mukund Trivedi
 
39f1b9a797dbms chapter2 b.sc2 (1)
39f1b9a797dbms chapter2 b.sc2 (1)39f1b9a797dbms chapter2 b.sc2 (1)
39f1b9a797dbms chapter2 b.sc2 (1)Mukund Trivedi
 

What's hot (15)

Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven Design
 
Data Modeling Er
Data Modeling ErData Modeling Er
Data Modeling Er
 
Lecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASELecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASE
 
2 er
2 er2 er
2 er
 
Understanding unified modelling language
Understanding unified modelling languageUnderstanding unified modelling language
Understanding unified modelling language
 
06 class diagrams
06 class diagrams06 class diagrams
06 class diagrams
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
 
07 intro2 oop
07 intro2 oop07 intro2 oop
07 intro2 oop
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modelling
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Model
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Behavioural modelling
Behavioural modellingBehavioural modelling
Behavioural modelling
 
Ch 5 O O Data Modeling
Ch 5  O O  Data ModelingCh 5  O O  Data Modeling
Ch 5 O O Data Modeling
 
39f1b9a797dbms chapter2 b.sc2
39f1b9a797dbms chapter2 b.sc239f1b9a797dbms chapter2 b.sc2
39f1b9a797dbms chapter2 b.sc2
 
39f1b9a797dbms chapter2 b.sc2 (1)
39f1b9a797dbms chapter2 b.sc2 (1)39f1b9a797dbms chapter2 b.sc2 (1)
39f1b9a797dbms chapter2 b.sc2 (1)
 

Similar to SAD02 - Object Orientation

PATTERNS01 - An Introduction to Design Patterns
PATTERNS01 - An Introduction to Design PatternsPATTERNS01 - An Introduction to Design Patterns
PATTERNS01 - An Introduction to Design PatternsMichael Heron
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - InheritanceMichael Heron
 
Object And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesObject And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesJessica Deakin
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docxFredWauyo
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented ProgramMichael Heron
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented DesignAravinth NSP
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptxUmerUmer25
 
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGN
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGNPROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGN
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGNijpla
 
Object Oriented Analysis And Design
Object Oriented Analysis And DesignObject Oriented Analysis And Design
Object Oriented Analysis And DesignSahil Mahajan
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagramskebsterz
 
SAD11 - Sequence Diagrams
SAD11 - Sequence DiagramsSAD11 - Sequence Diagrams
SAD11 - Sequence DiagramsMichael Heron
 
Ooad notes
Ooad notesOoad notes
Ooad notesNancyJP
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An OverviewRaj Thilak S
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering conceptsKomal Singh
 
What is OOP?
What is OOP?What is OOP?
What is OOP?Amin Uddin
 
dbms mannual.pdf
dbms mannual.pdfdbms mannual.pdf
dbms mannual.pdfDevidasBhere
 

Similar to SAD02 - Object Orientation (20)

PATTERNS01 - An Introduction to Design Patterns
PATTERNS01 - An Introduction to Design PatternsPATTERNS01 - An Introduction to Design Patterns
PATTERNS01 - An Introduction to Design Patterns
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
Object And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesObject And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) Languages
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
DISE - OOAD Using UML
DISE - OOAD Using UMLDISE - OOAD Using UML
DISE - OOAD Using UML
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptx
 
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGN
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGNPROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGN
PROPERTIES OF RELATIONSHIPS AMONG OBJECTS IN OBJECT-ORIENTED SOFTWARE DESIGN
 
Object Oriented Analysis And Design
Object Oriented Analysis And DesignObject Oriented Analysis And Design
Object Oriented Analysis And Design
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagrams
 
SAD11 - Sequence Diagrams
SAD11 - Sequence DiagramsSAD11 - Sequence Diagrams
SAD11 - Sequence Diagrams
 
Ooad notes
Ooad notesOoad notes
Ooad notes
 
Er Modeling
Er ModelingEr Modeling
Er Modeling
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering concepts
 
What is OOP?
What is OOP?What is OOP?
What is OOP?
 
dbms mannual.pdf
dbms mannual.pdfdbms mannual.pdf
dbms mannual.pdf
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
 

More from Michael Heron

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMichael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconductMichael Heron
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkMichael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility SupportMichael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael Heron
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - TexturesMichael Heron
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - ShadingMichael Heron
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)Michael Heron
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationMichael Heron
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsMichael Heron
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationMichael Heron
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - ModifiersMichael Heron
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IOMichael Heron
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - TemplatesMichael Heron
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - AbstractionMichael Heron
 

More from Michael Heron (20)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...gurkirankumar98700
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi đŸĢĻ HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi đŸĢĻ HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi đŸĢĻ HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi đŸĢĻ HOT AND SEXY VVIP 🍎 SE...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi đŸ’¯Call Us 🔝8264348440🔝
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑đŸŊ‍❤ī¸â€đŸ§‘đŸģ 89...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 

SAD02 - Object Orientation

  • 1. + Object Oriented Analysis Software Analysis and Design Michael Heron
  • 2. + Introduction īŽ In this lecture we’re going to begin discussing how we actually go about developing a complex program. īŽ And we’ll do it through the medium of object orientation. īŽ This is likely to be a somewhat alien way to approach a problem for many of you. īŽ One of the great lies of object orientation is that it is ‘easy because it mirrors the way people think’ īŽ However, it is the conceptual understanding that will enable you to build very complex programs as time goes by. īŽ It’s a very powerful way to build functionality.
  • 3. + An Object Oriented System īŽ A properly designed object oriented system consists of: īŽ One or more objects. īŽ These objects are defined by classes. īŽ Each object consists of: īŽ Attributes īŽ Behaviours īŽ Attributes contain information about the object. īŽ Data īŽ Behaviours are instructions for acting upon that data.
  • 4. + The Structure of an Object īŽ First, we must define what we mean by an object. īŽ In terms of object oriented programming. īŽ An object is an instance of a class. īŽ A class is like a blueprint telling the object what structure it has. īŽ A class defines: īŽ Attributes īŽ Behaviours īŽ The object defines īŽ The state of attributes. īŽ The values that each piece of data has.
  • 5. + Eh? īŽ Let’s look at in the abstract. īŽ There exists, somewhere, a blueprint for a chair. īŽ Blueprints for the chairs on which you are sitting. īŽ The blueprint defines what the chair looks like. īŽ It defines the structure of the chair īŽ It defines the relationship of the legs to the seat īŽ This blueprint would be the class. īŽ The specific chairs on which you are sitting would be objects. īŽ They were made (instantiated) from that blueprint.
  • 6. + Uhâ€Ļ īŽ The blueprint tells us how the chair is supposed to behave and what information about that chair may be mutable. īŽ The colour of the chair īŽ The material of the chair īŽ The size of the chair īŽ The class says: īŽ A chair has a colour, material, and size īŽ The object says: īŽ I am blue, made of leather, and am medium sized. īŽ Different chairs can have the same basic structure, but different states. īŽ I am pink, made of suede, and am large.
  • 7. + Okay! īŽ We’ll come back to this subject later. īŽ Because regardless of what people may tell you, object orientation does not come naturally to most people. īŽ This however is going to be the fundamental bedrock of the systems we analyse in the coming weeks. īŽ The programming languages you use throughout this course are object oriented languages. īŽ Visual Basic .NET īŽ Java īŽ C# īŽ The objects may not be emphasized to begin with. īŽ But they’re coming.
  • 8. + Attributes īŽ The class defines what attributes will be present in an object. īŽ It has these. īŽ We don’t know what they are yet. īŽ Attributes are things that an object will have. īŽ Usually things that are mutable (they can change). īŽ Consider a human face. īŽ It has eyes īŽ It has a nose īŽ It has a mouth īŽ These are modeled in a computer program as variables. īŽ A class is thus a collection of variables.
  • 9. + Behaviours īŽ As well as these variables, a class contains behaviours for acting upon those variables. īŽ If the class is a human face: īŽ Attributes: Eyes, Mouth, Nose īŽ Behaviours: blink, smile, sniff īŽ These are modeled in a computer program as functions. īŽ Also called methods. īŽ Two names for the same thing, we’ll use these interchangeably. īŽ Behaviours / Functions / Methods īŽ Different words, all for the same basic concept.
  • 10. + Behaviours īŽ Behaviours can be broken down into further parts. īŽ Behaviours may have variables of their own. īŽ Temporary variables that only exist as long as the method is executing. īŽ These are known as ‘local variables’ in programming. īŽ They have a limited scope within which they can be accessed. īŽ Behaviours will usually incorporate programming structures. īŽ Some structures allow the programmer to choose between courses of actions. īŽ Some structures allow the programmer to repeat blocks of code. īŽ Behaviours will incorporate flow control.
  • 11. + Class Diagrams īŽ One of the reasons why software development has such a complex vocabulary of jargon is the need for experts to communicate succinctly. īŽ This is what all formal software design techniques are about. īŽ In order for us to begin talking about how to discuss programs, we need some kind of share vocabulary. īŽ We don’t know how to really use them yet, but let’s talk about how we can represent a class in a modeling language. īŽ In this case, the language is UML īŽ Unified Modelling Language
  • 12. + Object Oriented Programs īŽ Object oriented programs introduce new complexities of interaction. īŽ Objects have a relationship to classes. īŽ Objects may be composed of other objects. īŽ Objects define their own behaviours and attributes. īŽ Objects can offer several levels of indirection to other objects. īŽ Gaining a clear perspective on how an object oriented program fits together is key to developing and maintaining OO code. īŽ Which is what our analysis and design eventually leads towards.
  • 13. + Object Relationships īŽ Objects can contain references to other objects. īŽ This is known as composition. īŽ This is a has a relationship. īŽ Composition relationships also imply a multiplicity (or cardinality). īŽ Where there is a 0 or 1 relationship, it is known as a composition. īŽ Where it is more, it is an aggregation. īŽ Formal UML notations have more precise differentiations of composition. īŽ That’s for Future Us to worry about.
  • 14. + Object Relationships īŽ An object may be a specialisation of another object. īŽ This is known as inheritance in object orientation. īŽ This is a is a relationship. īŽ More specialised forms of inheritance exist. īŽ We’ll talk about these as we go along. īŽ For now, we’ll just use the one kind. īŽ The class from which another class inherits is called the parent. īŽ Or Super class. īŽ The class that does the inheriting is called the child. īŽ Or sub class.
  • 15. + Examples īŽ A Car: īŽ Has an engine (composition) īŽ Has four wheels (aggregation) īŽ Has 2 or more doors (aggregation) īŽ Is a vehicle (inheritance) īŽ A Kitten: īŽ Has four legs (aggregation) īŽ Is an animal (inheritance) īŽ Has a tail (composition) īŽ Has the property of being as cute as the dickens (composition)
  • 16. + Object Oriented Programs īŽ The relationship between objects and classes becomes very complex in many computer programs. īŽ We’ll see this before too long when we return to our case study. īŽ Some means of representing this complexity ‘at a glance’ is useful. īŽ This is what a class diagram is used for. īŽ It gives the static view of a program’s architecture. īŽ It doesn’t change when the programming is running. īŽ Other techniques exist too. īŽ They vary in effectiveness.
  • 17. + Class Diagrams īŽ At their simplest, class diagrams are just boxes with lines connecting them to other boxes. īŽ They show the relationship between classes only.
  • 18. + Class Diagrams īŽ At the next level of usefulness, class diagrams also contain information about attributes and methods. īŽ Attributes in the second row īŽ Methods in the third īŽ At their best, class diagrams contain class relationships, methods, attributes, and the visibility of each. īŽ They also explicitly show multiplicity. īŽ Class diagrams are the most fundamental unit of UML. īŽ And also the most useful. īŽ If you only ever take one diagraming notation to heart, let it be this one.
  • 19. + Class Diagram with Attributes
  • 20. + Why Use A Class Diagram? īŽ There are several reasons why using a class diagram leads to a more complete view of a project. īŽ It shows the relationship between classes in a way that allows you to trace accessibility. īŽ It shows at a glance the amount of coupling in a project. īŽ It shows at a glance the amount of cohesion in a project. īŽ It shows at a glance the impact of change. īŽ These are elements that tell us ‘how good an OO design we have’ īŽ That’s an incredibly difficult thing to assess at the moment, which is one of the reasons why OOP is so hard to learn.
  • 21. + Coupling and Cohesion īŽ One of the biggest problems OO developers have is ensuring a good OO design. īŽ What is a good OO design, you ask? īŽ Certainly for people unfamiliar with how OO is best done, it’s hard to objectively rate an object architecture. īŽ ‘Uh, sure – it’s ten good?’ īŽ Two objective measures exist for this though. īŽ Coupling īŽ Cohesion īŽ As a rule, we are aiming for high cohesion and low coupling.
  • 22. + Coupling īŽ Coupling relates to the amount of interconnectedness of classes. īŽ We want this to be as low as is reasonably possible. īŽ There’s a reason why we don’t just link classes up in every possible way. īŽ A coupling relationship is any composition, aggregation, or inheritance. īŽ We can’t get away from these, but we can limit them. īŽ The more connections made between objects and classes, the harder it is to make any changes. īŽ Because of the knock-on effect associated.
  • 23. + Coupling īŽ If your program has high coupling, there are several disadvantages built in: īŽ Changes in one object may result in unexpected side-effects elsewhere in a program. īŽ Often the cause is not at all obvious. īŽ Classes are difficult to understand at a glance. īŽ They make use of so much external functionality. īŽ Classes are difficult to test. īŽ They cannot be easily extracted from their context. īŽ We aim for low coupling, of the right kind of coupling. īŽ More on that later.
  • 24. + Cohesion īŽ Cohesion is the level to which an object adheres to a single set of responsibilities. īŽ We want this as high as is reasonably possible. īŽ In a good object oriented program, each object has one firmly defined responsibility. īŽ A cat object would not be responsible for keeping track of its owner’s employment. īŽ A car object would not be responsible for storing the name of the garage where it gets services. īŽ Good OO design requires us to make classes that have unique, specific responsibilities.
  • 25. + Cohesion īŽ The dangers that come from low cohesion are the same as that of high coupling. īŽ They’re really just two ways of reflecting the same basic concept. īŽ Low cohesion is an insidious problem. īŽ Programs with low cohesion tend to become even less coherent over time. īŽ It is a consequence of badly analysed and badly designed programs. īŽ You’ll learn how to do this properly in third year.
  • 26. + The Tension of OO Development īŽ Object Oriented programs are a tension between coupling and cohesion. īŽ We increase cohesion by increasing coupling. īŽ We reduce coupling by decreasing cohesion. īŽ As OO developers we have to find a happy medium between the two. īŽ In some cases, simple rationalization of a design can remove problems. īŽ That is a judgment call that comes from experience. īŽ We’ll have plenty of opportunities to do this as we go through the module.
  • 27. + Impact of Change īŽ Both of these concepts are a way of objectively rating the impact of change in a program. īŽ What makes a program easy to work with? īŽ Clearly written code. īŽ Comments (seriously) īŽ Changes do not have unexpected consequences. īŽ The latter of these three is what the impact of change defines. īŽ That when we change a piece of code, we know what is going to be changed as a result of it.
  • 28. + Impact of Change īŽ One of the reasons we restrict visibility of variables and methods is to manage the impact of change. īŽ If you are a Respectful Developer, you avoid making changes that will impact on code you did not write. īŽ Lest terrible vengeance be visited upon you and your kith and kin īŽ The lower the visibility, the better. īŽ Changing a local variable for example only impacts the method in which it is defined. īŽ Changing a class wide attribute will potentially impact on every method in the class.
  • 29. + Impact of Change īŽ In a multi-developer environment you have to assume that if functionality is available, it has been used. īŽ Someone saw your calculate_awesome() method and thought ‘hey, that does exactly what I want’ īŽ If it can be used, you can’t idly make structural changes. īŽ Refactoring is fine īŽ Redesign is not īŽ We’ll talk more about refactoring in a later lecture. īŽ It basically means ‘improving code so well that nobody notices’
  • 30. + The Class Diagram īŽ The best quality of class diagrams shows the impact of change at a glance. īŽ Where there are lots of arrows, there be coupling issues. īŽ Where there are huge lists of methods and attributes in a class, there be likely cohesion problems. īŽ Where there are lots of public methods and attributes, there be likely impact of change issues. īŽ Doing the class diagram from the start gives us a good opportunity to identify structural problems before we write a single line of code.
  • 31. + The Class Diagram īŽ In multi-developer projects, the class diagram represents the ‘best understanding’ of how a program is being developed. īŽ It’s kind of an informal contract with your fellow developers. īŽ One of the benefits we get from object orientation is an ease of development and integration. īŽ But only if everyone is communicating effectively. īŽ It is important that this diagram remain up to date with the state of the program. īŽ It is a ‘living document’. īŽ Some tools exist for automatically generating them. īŽ And generating program code from class diagrams.
  • 32. + Conclusion īŽ Class diagrams are awesome. īŽ Seriously, you need to believe me on that. īŽ They give us a neat way of representing a number of issues with our programs. īŽ How classes relate īŽ The degree of coupling īŽ The degree of cohesion īŽ The likely impact of change. īŽ We can tell at a glance when our systems are going off the rails. īŽ Huzzah.